﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

namespace AppToolkit.WF.Services
{

    /// <summary>
    /// Activity that allows notifying some progress to an observer outside the workflow.
    /// </summary>
    public class ProgressActivity : CodeActivity
    {
        /// <summary>
        /// Current value [0;Maximum]
        /// </summary>
        [RequiredArgument]
        public InArgument<Int32> Current { get; set; }

        /// <summary>
        /// Maximum value that must be reached for the workflow to complete.
        /// </summary>
        [RequiredArgument]
        public InArgument<Int32> Maximum { get; set; }

        /// <summary>
        /// If your activity returns a value, derive from CodeActivity&lt;TResult&gt;
        /// and return the value from the Execute method.
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            var current = context.GetValue(this.Current);
            var maximum = context.GetValue(this.Maximum);

            context.Track(new ProgressTrackingRecord() 
            {
                Current=current,
                Maximum=maximum,
            });
        }
    }
}
